package com.example.administrator.bleapp.adapter;

import android.support.annotation.Nullable;
import android.text.TextUtils;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.administrator.bleapp.R;
import com.vise.baseble.model.BluetoothLeDevice;
import com.vise.baseble.utils.HexUtil;

import java.util.List;

/**
 * Created by MaDeng on 2017/12/18.
 */

public class DeviceListAdapter extends BaseQuickAdapter<BluetoothLeDevice,BaseViewHolder> {
    public DeviceListAdapter(@Nullable List<BluetoothLeDevice> data) {
        super(R.layout.item_scan_layout,data);
    }

    @Override
    protected void convert(BaseViewHolder helper, BluetoothLeDevice item) {
        if (item != null && item.getDevice() != null) {
            String deviceName = item.getDevice().getName();
            helper.setText(R.id.device_name, !TextUtils.isEmpty(deviceName)?deviceName:"Unknown device")
                    .setText(R.id.device_mac,item.getDevice().getAddress())
                    .setText(R.id.device_rssi,"RSSI:"+item.getRssi() + "dB")
                    .setText(R.id.device_scanRecord,"Scan Record"+ HexUtil.encodeHexStr(item.getScanRecord()));
        }
    }
}
